use crate::src::src::queue::{
    queue_free, queue_is_empty, queue_new, queue_peek_head, queue_peek_tail, queue_pop_head,
    queue_pop_tail, queue_push_head, queue_push_tail,
};
use crate::src::struct_and_type::{Queue, QueueValue, UnitTestFunction};
use crate::src::test::alloc_testing::alloc_test_set_limit;
use crate::src::test::framework::run_tests;

extern "C" {}
#[no_mangle]
pub static mut variable1_test_queue: i32 = 0;
#[no_mangle]
pub static mut variable2_test_queue: i32 = 0;
#[no_mangle]
pub static mut variable3_test_queue: i32 = 0;
#[no_mangle]
pub static mut variable4_test_queue: i32 = 0;
#[no_mangle]
pub extern "C" fn generate_queue() -> *mut Queue {
    let mut queue: *mut Queue = 0 as *mut Queue;
    let mut i: i32 = 0;
    queue = queue_new();
    i = 0 as i32;
    while i < 1000 as i32 {
        queue_push_head(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue,
        );
        i += 1;
        i;
    }
    return queue;
}
#[no_mangle]
pub extern "C" fn test_queue_new_free() {
    let mut i: i32 = 0;
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    queue_free(queue);
    queue = queue_new();
    i = 0 as i32;
    while i < 1000 as i32 {
        queue_push_head(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
        );
        i += 1;
        i;
    }
    queue_free(queue);
    alloc_test_set_limit(0 as i32);
    queue = queue_new();
    assert!(queue.is_null());
}
#[no_mangle]
pub extern "C" fn test_queue_push_head() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    let mut i: i32 = 0;
    queue = queue_new();
    i = 0 as i32;
    while i < 1000 as i32 {
        queue_push_head(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_head(
            queue,
            (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue,
        );
        i += 1;
        i;
    }
    assert!(queue_is_empty(queue) == 0);
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
    );
    queue_free(queue);
    queue = queue_new();
    alloc_test_set_limit(0 as i32);
    assert!(
        queue_push_head(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        ) == 0
    );
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_pop_head() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    assert!((queue_pop_head(queue)).is_null());
    queue_free(queue);
    queue = generate_queue();
    while queue_is_empty(queue) == 0 {
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
    }
    assert!((queue_pop_head(queue)).is_null());
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_peek_head() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    assert!((queue_peek_head(queue)).is_null());
    queue_free(queue);
    queue = generate_queue();
    while queue_is_empty(queue) == 0 {
        assert!(
            queue_peek_head(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_head(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_head(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_head(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_head(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
    }
    assert!((queue_peek_head(queue)).is_null());
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_push_tail() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    let mut i: i32 = 0;
    queue = queue_new();
    i = 0 as i32;
    while i < 1000 as i32 {
        queue_push_tail(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_tail(
            queue,
            (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_tail(
            queue,
            (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue,
        );
        queue_push_tail(
            queue,
            (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue,
        );
        i += 1;
        i;
    }
    assert!(queue_is_empty(queue) == 0);
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_head(queue) == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
    );
    assert!(
        queue_pop_tail(queue) == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
    );
    queue_free(queue);
    queue = queue_new();
    alloc_test_set_limit(0 as i32);
    assert!(
        queue_push_tail(
            queue,
            (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        ) == 0
    );
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_pop_tail() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    assert!((queue_pop_tail(queue)).is_null());
    queue_free(queue);
    queue = generate_queue();
    while queue_is_empty(queue) == 0 {
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
    }
    assert!((queue_pop_tail(queue)).is_null());
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_peek_tail() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    assert!((queue_peek_tail(queue)).is_null());
    queue_free(queue);
    queue = generate_queue();
    while queue_is_empty(queue) == 0 {
        assert!(
            queue_peek_tail(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_tail(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable2_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_tail(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable3_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_peek_tail(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
        assert!(
            queue_pop_tail(queue)
                == (unsafe { &mut variable4_test_queue }) as *mut i32 as QueueValue
        );
    }
    assert!((queue_peek_tail(queue)).is_null());
    queue_free(queue);
}
#[no_mangle]
pub extern "C" fn test_queue_is_empty() {
    let mut queue: *mut Queue = 0 as *mut Queue;
    queue = queue_new();
    assert!(queue_is_empty(queue) != 0);
    queue_push_head(
        queue,
        (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
    );
    assert!(queue_is_empty(queue) == 0);
    queue_pop_head(queue);
    assert!(queue_is_empty(queue) != 0);
    queue_push_tail(
        queue,
        (unsafe { &mut variable1_test_queue }) as *mut i32 as QueueValue,
    );
    assert!(queue_is_empty(queue) == 0);
    queue_pop_tail(queue);
    assert!(queue_is_empty(queue) != 0);
    queue_free(queue);
}
static mut tests_test_queue: [UnitTestFunction; 9] = {
    [
        Some(test_queue_new_free as unsafe extern "C" fn() -> ()),
        Some(test_queue_push_head as unsafe extern "C" fn() -> ()),
        Some(test_queue_pop_head as unsafe extern "C" fn() -> ()),
        Some(test_queue_peek_head as unsafe extern "C" fn() -> ()),
        Some(test_queue_push_tail as unsafe extern "C" fn() -> ()),
        Some(test_queue_pop_tail as unsafe extern "C" fn() -> ()),
        Some(test_queue_peek_tail as unsafe extern "C" fn() -> ()),
        Some(test_queue_is_empty as unsafe extern "C" fn() -> ()),
        None,
    ]
};
fn main_0_test_queue(mut _argc: i32, mut _argv: *mut *mut i8) -> i32 {
    run_tests(unsafe { tests_test_queue.as_mut_ptr() });
    return 0 as i32;
}
pub fn main_test_queue() {
    let mut args: Vec<*mut i8> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    {
        ::std::process::exit(main_0_test_queue(
            (args.len() - 1) as i32,
            args.as_mut_ptr() as *mut *mut i8,
        ) as i32)
    }
}
